﻿/*
 * $Id: schedule.h 454 2010-08-02 18:38:16Z cmtonkinson@gmail.com $
 *
 * This file is part of the Symphony project <http://code.google.com/p/symphonymud/>
 * Copyright 2005-2010 Chris Tonkinson <cmtonkinson@gmail.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef H_SYMPHONY_SCHEDULE
#define H_SYMPHONY_SCHEDULE

#include <set>
#include "event-handler-method.h"
#include "job.h"

using std::multiset;

class Schedule {
  public:
    Schedule( void );
    virtual ~Schedule( void );

    void add( Job* job );

    template <class EventType>
    void schedule( time_t when, bool (*function)( EventType* ) ) {
      if ( function ) {
        _queue.insert( new Job( when, new EventHandlerFunction<EventType>( function ) ) );
      }
      return;
    }

    template <class ObjectType,class EventType>
    void schedule( time_t when, ObjectType* object, bool (ObjectType::*method)( EventType* ) ) {
      if ( object && method ) {
        _queue.insert( new Job( when, new EventHandlerMethod<ObjectType,EventType>( object, method ) ) );
      }
      return;
    }

    bool  fire( void );
    long  size( void ) const;

  private:
    multiset<Job*,JobComp> _queue;
};

#endif // #ifndef H_SYMPHONY_SCHEDULE
